/*
 * @Author: Binggan
 * @Date: 2020-03-01 12:09:23
 * @LastEditors: Binggan
 * @LastEditTime: 2020-03-06 19:31:40
 * @Description: 
 */
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex);

const state = {
    serviceUrl: "http:" + process.env.API_ROOT,
    user: sessionStorage.getItem('user') ? JSON.parse(sessionStorage.getItem('user')) :null,//{name:"admin",role:0} 
    activeMenu: sessionStorage.getItem('actMenu') || '1',
    equipTypes: ["可回收垃圾", "有害垃圾", "厨余垃圾", "其它垃圾"],

    slideMenu: false,
    roles: [{ id: 1, name: '系统管理员' }, { id: 2, name: '普通用户' }, { id: 3, name: '回收者' }],
    editPaperId: null,
    
};


const ADD_COUNT = 'ADD_COUNT'; // 用常量代替事件类型，使得代码更清晰
const REMOVE_COUNT = 'REMOVE_COUNT';
const mutations = {
    [ADD_COUNT](state, user) {//登录记录当前用户
        console.log(user)
        sessionStorage.setItem('user', JSON.stringify(user))
        state.user = user;
    },
    [REMOVE_COUNT](state, user) {//退出登录
        sessionStorage.removeItem('user');
        state.user = null;
        sessionStorage.removeItem('actMenu');
        state.activeMenu = '1';
    },
    setActiveMenu(state, val) {//目录激活状态
        sessionStorage.setItem('actMenu', val);
        state.activeMenu = val;
    }
};

const getters = {};

const actions = {

};

export default new Vuex.Store({
    state,
    mutations,
    getters,
    actions
})
